
import { APILogin } from './fetch.js';
import { setCookie,getCookie } from './tools.js';

layui.use(['layer'], function () {
    var layer = layui.layer
    $('#btn1').click(function () {
        var username = $('#username').val();
        var password = $('#password').val()
        // console.log(username, password);
        var timer = null
        APILogin({
            username,
            password
        }).then(({code,msg}) => {
            // console.log(data);
            if (code) {
                layer.msg(msg);
                setCookie('login_user',username)
                //从哪里来到哪里去
                clearTimeout(timer);
                timer = setTimeout(() => {
                var back = sessionStorage.back || 'http://127.0.0.1:5500/2004/sweetheart/html/index.html';
                    location.href = back 
                }, 1000)
            } else {
                layer.msg(msg)
            }
        })
    })
    
   
   

})